<!DOCTYPE html>
<html lang="">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Title Page</title>

    <!-- Bootstrap CSS -->
    <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
    <style>
       div{
           margin-bottom: 100px;
       }
    </style>
</head>

<body>

    <div class="text-center">
        <button type="button" class="btn btn-success" id="play">播放</button>

    <button type="button" class="btn btn-danger" id="stop">停止</button>
    </div>

    <h1 class="text-center">Hello World</h1>

    <!-- jQuery -->
    <script src="node_modules/jquery/dist/jquery.min.js"></script>
    <!-- Bootstrap JavaScript -->
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <script>

        $(function (e) {
            let n = 0;
            let timer = null;
            timer =  setInterval(() => {
                n += 10;
                $('h1').css({
                    transform: 'rotate(' + n + 'deg)'
                })
            }, 100);
            // 停止
            $('#stop').click(function (e) { 
                e.preventDefault();
                clearInterval(timer)
            });
            //播放
            $('#play').click(function (e) { 
                clearInterval(timer)
                e.preventDefault();
                timer =  setInterval(() => {
                n += 10;
                $('h1').css({
                    transform: 'rotate(' + n + 'deg)'
                })
            }, 100);
            });
        })
    </script>
</body>

</html>